﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// 文件名：ClsAreaSetDAL.cs
/// 作  者：SAM/SAM
/// 时  间：2006.11.10
/// 说  明：ClsAreaSetDAL类用于区域设置信息相关处理
/// </summary>
public class ClsAreaSetDAL
{
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    #region 地区信息管理

    /// <summary>
    /// 获取所有的区域设置币别信息
    /// </summary>
    /// <returns>返回区域设置信息数据集</returns>
    public DataSet GetAreaSets()
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetDataSetArea", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 搜索区域设置信息
    /// </summary>
    /// <param name="Key">搜索关键字</param>
    /// <returns>返回搜索信息数据集</returns>
    public DataSet SearchAreaSets(string Key)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_SearchAreaSets", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@key", Key);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 作废区域设置信息
    /// </summary>
    /// <param>区域设置编号</param>
    /// <param name="Is_Visible">作废状态1为临时作废，－1为彻底作废</param>
    /// <returns>返回作废是否成功</returns>
    public Boolean DeleteAreaSet(string ID, int Is_Visible)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteAreaSet", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Ik_Id", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Id"].Value = ID;
        com.Parameters.Add("@Is_Visible", SqlDbType.Int, 1);
        com.Parameters["@Is_Visible"].Value = Is_Visible;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 确认区域设置信息
    /// </summary>
    /// <param>区域设置编号</param>
    /// <param name="AuditStat">确认状态</param>
    /// <param name="Auditor">确认人</param>
    /// <returns>返回确认是否成功</returns>
    public Boolean AuditStatAreaSet(string ID, int AuditStat, string Auditor)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AuditStatSetAreaSet", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Ik_Id", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Id"].Value = ID;
        com.Parameters.Add("@is_audit", SqlDbType.Int);
        com.Parameters["@is_audit"].Value = AuditStat;
        com.Parameters.Add("@auditor", SqlDbType.NVarChar, 60);
        com.Parameters["@auditor"].Value = Auditor;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 增加区域设置信息
    /// </summary>
    /// <param>区域设置编号</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    public Boolean AddAreaSet(string ID, string Up ,string Name, string Remark, string Oper)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddAreaSet", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Ik_Id", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Id"].Value = ID;
        com.Parameters.Add("@Ik_Up", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Up"].Value = Up;
        com.Parameters.Add("@Ik_Name", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Name"].Value = Name;

        //中间插入各表的数据和参数

        com.Parameters.Add("@Oper", SqlDbType.NVarChar, 60);
        com.Parameters["@Oper"].Value = Oper;
        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = Remark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 修改区域设置信息
    /// </summary>
    /// <param>区域设置编号</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    public Boolean UpDateAreaSet(string ID, string Up, string Name, string Remark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_UpDateAreaSet", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Ik_Id", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Id"].Value = ID;
        com.Parameters.Add("@Ik_Up", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Up"].Value = Up;
        com.Parameters.Add("@Ik_Name", SqlDbType.NVarChar, 20);
        com.Parameters["@Ik_Name"].Value = Name;

        //中间插入各表的数据和参数

        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = Remark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 用于区域设置查询窗口获取数据
    /// </summary>
    /// <returns></returns>
    public DataSet SearchAreaSets()
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_QueryWinGetDataByAreaData", con);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    #endregion

    #region 地区部门设置

    /// <summary>
    /// 根据地区编号获取该地区的部门设置信息
    /// </summary>
    /// <param name="AreaNo">地区编号</param>
    /// <returns></returns>
    public DataSet GetDeptDataSetByArea(string AreaNo)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetDeptDataSetByArea", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@area_no", SqlDbType.NVarChar, 50);
        dat.SelectCommand.Parameters["@area_no"].Value = AreaNo;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 新增地区部门设置
    /// </summary>
    /// <param name="AreaNo">地区编号</param>
    /// <param name="DeptNo">部门编号</param>
    /// <returns></returns>
    public Boolean AddDeptSetByArea(string AreaNo, string DeptNo)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddDeptSetByArea", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@area_no", SqlDbType.NVarChar, 50);
        com.Parameters["@area_no"].Value = AreaNo;
        com.Parameters.Add("@dept_no", SqlDbType.NVarChar, 50);
        com.Parameters["@dept_no"].Value = DeptNo;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 作废区域部门设置信息
    /// </summary>
    /// <param name="ID">部门设置ID</param>
    /// <returns>返回作废是否成功</returns>
    public Boolean DeleteDeptSetByArea(int ID)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteDeptSetByArea", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@id", SqlDbType.Int, 4);
        com.Parameters["@id"].Value = ID;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    #endregion
}
